home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13290 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: solon.com!not-for-mail
  2. From: schwarz@mips.complang.tuwien.ac.at (Konrad Schwarz)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated,hp.unix,comp.sys.hp.apps,comp.sys.hp.hpux
  4. Subject: Re: C coding problem
  5. Date: 6 Apr 1996 08:41:56 -0600
  6. Organization: TU Wien
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4k5vrk$a2d@solutions.solon.com>
  10. References: <4j06na$808@solutions.solon.com> <4jttan$3gf@solutions.solon.com> <4jv6st$crf@solutions.solon.com> <4k1qh3$5hn@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12.  
  13. In article <4k1qh3$5hn@solutions.solon.com>, news@Thinkage.On.CA writes:
  14.  
  15. |> However it is not always so that the machine does a distinct
  16. |> add or multiply in order to handle a[i].  The "*p++" idiom may look
  17. |> shot in the C code, and on a PDP-11 it usually resulted in nice
  18. |> short code.  However, there is no guarentee that this is true of all
  19. |> hardware.  It is not all that uncommon to have an architecture where
  20. |> adding 1 to an int is much cheaper than adding one to a pointer,
  21.  
  22. Examples?  The dominant trend in computer architecture seems to be the
  23. reduced instruction set with simple addressing modes; Mips and Alpha
  24. are two architectures that do not have an indexed addressing mode.
  25.  
  26. |> In such and environment, 
  27. |>       *q++ = *p++;
  28. |> loses badly to
  29. |>       q[i] = p[i], ++i;
  30. |> if the hardware indexing works in terms of the objects being
  31. |> referenced.
  32.  
  33. Note that indexed addressing often works only for small
  34. powers of two, e.g., x86 family.
  35.  
  36. |> Pointer notation can greatly reduce program
  37. |> clutter so you can see what is happening.
  38.  
  39. Agreed. :)
  40.  
  41. Konrad Schwarz
  42.